package com.peng.sparktest.sparkstreaming

import java.io.{OutputStream, PrintStream}
import java.net.{ServerSocket, Socket}

object MyServer {
  def main(args: Array[String]): Unit = {
    val server = new ServerSocket(8888)
    println("start server~")
    while (true) {
      val socket: Socket = server.accept()
      println("a client connect~！")

      new Thread() {

        override def run(): Unit = {

          var num = 0

          while (socket.isConnected) {

            num += 1

            val outputStream: OutputStream = socket.getOutputStream

            val printStream = new PrintStream(outputStream)

            printStream.println(s"hello ${num}")
            printStream.println(s"hello ${num}")
            printStream.println(s"world ${num}")

            Thread.sleep(1000)
          }


        }
      }.start()
    }
  }
}
